#!/bin/bash

# 定义项目名称，可根据实际情况修改
PROJECT_NAME="lightshare"

# 定义目标平台和架构
PLATFORMS=(
    "windows/amd64"
    "windows/386"
    "linux/amd64"
    "linux/386"
    "linux/arm64"
    "darwin/amd64"
    "darwin/arm64"
)

# 创建输出目录
mkdir -p bin

# 遍历平台和架构列表进行编译
for PLATFORM in "${PLATFORMS[@]}"; do
    IFS='/' read -r OS ARCH <<< "$PLATFORM"
    echo "正在编译 $OS $ARCH 版本..."
    OUTPUT_NAME="$PROJECT_NAME-$OS-$ARCH"
    if [ "$OS" == "windows" ]; then
        OUTPUT_NAME="$OUTPUT_NAME.exe"
    fi
    env GOOS="$OS" GOARCH="$ARCH" go build -ldflags "-s -w" -o "bin/$OUTPUT_NAME"
    if [ $? -eq 0 ]; then
        echo "$OS $ARCH 版本编译成功，输出文件: bin/$OUTPUT_NAME"
    else
        echo "$OS $ARCH 版本编译失败"
    fi
done

echo "编译完成"
